import axios from 'axios'

// -------------------------------学校-----------------------------
async function addEnrollment(enrollmentInfo) {
    const resp = await axios.post('/api/school/addEnrollment', enrollmentInfo, {
        params: {
            schoolWeID: localStorage.getItem('schoolWeID')
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

async function deleteEnrollment(studentNumber) {
    const resp = await axios.delete('/api/school/deleteEnrollment', {
        params: {
            studentNumber: studentNumber
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

async function enrollmentExist(studentNumber, schoolName) {
    const resp = await axios.get('/api/school/enrollmentExist', {
        params: {
            studentNumber: studentNumber,
            schoolName: schoolName
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

// -------------------------------学生----------------------------
async function getEnrollment(schoolName, studentNumber) {
    const resp = await axios.get('/api/student/getEnrollment', {
        params: {
            schoolName: schoolName,
            studentNumber: studentNumber
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

async function downloadEnrollment(studentNumber) {
    const resp = await axios.get('/api/student/downloadEnrollment', {
        params: {
            studentNumber: studentNumber
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}


export default {
    addEnrollment, deleteEnrollment, getEnrollment, downloadEnrollment, enrollmentExist
}